package ycl.security.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;
import ycl.common.result.REnum;
import ycl.common.result.Result;
import ycl.common.utils.ServletUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录未授权
 *
 * @author ycl
 * @date 2022-03-10 13:16:22
 */
@Component
@Slf4j
public class AuthAccessDeniedHandler implements AccessDeniedHandler {
	@Override
	public void handle(
			HttpServletRequest request,
			HttpServletResponse response,
			AccessDeniedException e) throws IOException {
		log.info("NoPermissionProviderHandler . handle . 无权限处理");
		Result<Object> result = Result.fail(REnum.USED_PAYMENT_REQUIRED);
		ServletUtil.writeResponse(response, result);
	}
}
